package com.sunday.authorization.security.userdetails;

import com.sunday.authorization.security.tools.userdetails.UserInfo;
import com.sunday.common.core.gson.GsonUtils;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;

import java.util.Collection;

/**
 * @Description: 当前授权用户
 */
@Slf4j
public class CustomUser extends User {

    // 用户信息
    @Getter
    @Setter
    private UserInfo userInfo;

    public CustomUser(String username, String password, Collection<? extends GrantedAuthority> authorities, UserInfo userInfo) {
        super(username, password, authorities);
        this.userInfo = userInfo;
    }

    public CustomUser(String username, String password, boolean enabled, boolean accountNonExpired,
                      boolean credentialsNonExpired, boolean accountNonLocked,
                      Collection<? extends GrantedAuthority> authorities, UserInfo userInfo) {
        super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities);
        this.userInfo = userInfo;
    }

    @Override
    public String toString() {
        return GsonUtils.DEFAULT.toJson(this);
    }

}
